<?php 
	if(!isset($batchLimit))
	{
		$batchLimit = 40;
	}
?>
<div class="infoMsg">
	<?php echo __("Batch will be processed till this window is open or till all records get saved.In case this windows get closed, batch process can be resumed again.") ?>
</div>
<strong>
	<?php echo sprintf(__("Importing %s file in batch of %d"),$fileInfo['other_information']['importData']['actual_file_name'],$batchLimit)?>
</strong>

<div id="running" style="display: none">
	<?php echo $html->image('/effects/img/circularAnimation.gif')?> <?php echo __("Running batch.....") ?>
</div>
<strong><?php echo __("Logs")?></strong>
<br />
<strong><?php echo __("Last Saved Id")?></strong>: <span id="lastSavedId"></span>
<textarea id="log_area" rows="20" col="40">
	
</textarea>

<script>
	$(document).ready(function(){
		
		runBatch() ;
	});
	var isBatchRunning = false;
	function runBatch()
	{
		if(isBatchRunning)
		{
			console.log("Batch already running");
			return;
		}
		var batchUrl = "<?php echo $html->url(array("action"=>"runBatch",$fileId,$batchLimit))?>";
		$('#running').show();
		isBatchRunning = true;
		$.getJSON(batchUrl,function(response){
			console.log(response);
			isBatchRunning = false;
			$("#log_area").val($("#log_area").val()+response.logs);
			$("#running").hide();
			if(!response.completed && response.ok)
			{
				setTimeout(runBatch,200);	
			}else if(response.completed)
			{
				alert("<?php echo __("Importing has been completed")?>");
			}else 
			{
				alert("<?php echo __("There is some problem in the batch please see the logs.")?>");
			}
		})
	}
</script>